import time
from selenium.webdriver.support.wait import WebDriverWait


class Base:
    def __init__(self, driver):
        self.driver = driver

    def base_find_element(self,loc,timeout=30,poll=1):
        return WebDriverWait(self.driver, timeout=timeout, poll_frequency=poll).\
            until(lambda x: x.find_element(*loc))

    def base_click(self, loc):
        self.base_find_element(loc).click()

    def base_input(self,loc,value):
        ip = self.base_find_element(loc)
        ip.clear()
        ip.send_keys(value)


     #查找元素
    def base_search(self,loc):
        return self.base_find_element(loc)

    def base_get_text(self,loc):
        return self.base_find_element(loc).text

    #截屏
    def base_get_image(self):
        self.driver.get_screenshot_as_file("../image/{}.png".format(time.strftime("%Y_%m_%d %H_%M_%S")))